Timer: The timer control will execute client side event s at specific interval and allows specific part so your page to update or refresh at these moments.
How we implement the Timer server control
Step1: we use the following control on aspx page
Example:
<body>
<form id="form1" runat="server">
<div>
<%--Using ScriptManger Control--%>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<%--Using UpdatePanel Control--%>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<%-- Using Label And Timer Control inside UpdatePanel--%>
<asp:Label ID="lblDateTime" runat="server" Text=""> </asp:Label>
<asp:Timer ID="Timer1"runat="server"Interval="9000"OnTick= "Timer1_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
Step2: We write the following code on Timer1_Tick event.
Example:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
lblDateTime.Text ="Start DateTime: "+ DateTime.Now.ToString();
}
}
protectedvoid Timer1_Tick(object sender, EventArgs e)
{
lblDateTime.Text ="By Timer: "+ DateTime.Now.ToString();
}
Step3: Run the project
Output:
After Sometimes, the output is:
This is the simple example of Timer and UpdatePanel control, how we use these control in our web based project or window based project.
Rahul Roi
19-Oct-2019This article is so nice for knowledge.
Sunil Singh
10-Jul-2017This article is truly nice.